<template>

  <div>
    <div v-show="!isAdd" class="main">
      <div style="display: block;overflow: hidden;">
        <el-button type="primary" style="float: left" @click="toAdd">新增</el-button>
        <el-button type="primary" style="float: right;" @click="getList">搜索</el-button>
        <el-input style="float:right;display: inline-block;width: 200px" v-model="realName"
                  placeholder="请输入姓名"></el-input>
      </div>
      <el-table :data="list" border style="width: 100%;margin-top: 20px">
        <el-table-column width="50" prop="id" label="序号"></el-table-column>
        <el-table-column prop="realName" label="姓名"></el-table-column>
        <el-table-column prop="linkphone" label="联系方式"></el-table-column>
        <el-table-column prop="accountName" label="账号"></el-table-column>
        <el-table-column prop="password" label="密码"></el-table-column>
        <el-table-column prop="groupId" label="所属岗位"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <span @click="toAdd(scope.row)">{{$t('action.edit')}}</span>
            <span @click="changeStatus(scope.row)">{{$t('action.disable')}}</span>
            <span @click="toDel(scope.row)">{{$t('action.delete')}}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination style="float: right;margin: 10px 0" background pageZize="10" @current-change="getList"
                     layout="prev, pager, next" :total="count">
      </el-pagination>
    </div>
    <AddAccount v-if="isAdd" :id="postId" @closePop="close"/>
  </div>
</template>

<script>
  import AddAccount from "./model/AddAccount";

  export default {
    name: "index",
    components: {AddAccount},
    data(){
      return {
        realName:'',
        isAdd: false,
        count: 0,
        list: [],
        changeSortIndex: null,
        postId: null
      }
    },
    created() {
      this.init(this.$route.query.realName || this.realName)
    },
    methods:{
      init(groupName){
        this.getList(groupName);
      },
      getList(realName) {
        this.$api.account.getAccountList({realName:realName?realName+":":""}).then(
          res => {
            this.list = res.data.list;
            this.count = res.data.count;
          }
        )
      },
      toAdd(){
        this.isAdd = true
      },
      changeStatus(){
        this.isAdd = true
      },
      toDel(){},
      close(data){
        this.isAdd = false
      },
    }
  }
</script>

<style scoped>

</style>
